package org.dromara.iot.controller;

import org.dromara.iot.handler.ReceiverMessageHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

@RestController
public class IotStreamEventController {

    private final ReceiverMessageHandler receiverMessageHandler;

    public IotStreamEventController(ReceiverMessageHandler receiverMessageHandler) {
        this.receiverMessageHandler = receiverMessageHandler;
    }

    @GetMapping("/sse/rfid")
    public SseEmitter handleRfid() {
        SseEmitter emitter = new SseEmitter(0L);
        receiverMessageHandler.addEmitter(emitter);
        return emitter;
    }
}
